package com.yp.shopping.controller;


import com.yp.shopping.bean.Result;
import com.yp.shopping.service.GoodsService;
import com.yp.shopping.vo.GoodsV;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    //获取所有商品
    @RequestMapping(value = "/getAllGoods", method = RequestMethod.GET)
    @ResponseBody
    public List<GoodsV> getAllGoods() {

        return goodsService.getAllGoods();
    }

    //通过id获取商品
    @RequestMapping(value = "/getGoodsById", method = RequestMethod.GET)
    @ResponseBody
    public GoodsV getGoodsById(Integer id) {

        return goodsService.getGoodsById(id);
    }

    //通过id删除商品
    @RequestMapping(value = "/deleteGoodsById", method = RequestMethod.GET)
    @ResponseBody
    public Result deleteGoodsById(Integer id) {

        return goodsService.deleteGoodsById(id);
    }


    //添加或添加商品
    @RequestMapping(value = "/saveOrUpdateGoods", method = RequestMethod.POST)
    @ResponseBody
    public Result saveOrUpdateGoods(@RequestBody GoodsV goodsV) {

        return goodsService.saveOrUpdateGoods(goodsV);
    }
}
